I didn't optimize this, but at least making a solution only takes half an hour.